package cn.school.workmgr.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.school.common.utils.SysUserUtils;
import cn.school.hotel.entity.TripHotel;
import cn.school.studyManage.entity.StudentBehaviorCfg;
import cn.school.workmgr.dao.RecruitMajorDao;
import cn.school.workmgr.entity.HygieneDormitory;
import cn.school.workmgr.entity.RecruitMajor;
import cn.school.workmgr.service.RecruitMajorService;
import cn.school.workmgr.vo.RecruitMajorVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

@Service
public class RecruitMajorServiceImpl extends ServiceImpl<RecruitMajorDao, RecruitMajor> implements RecruitMajorService {

    @Override
    public IPage<RecruitMajor> pageList(RecruitMajorVO vo) {
        LambdaQueryWrapper<RecruitMajor> wrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(vo.getMajorName())){
            wrapper.eq(RecruitMajor::getMajorName,vo.getMajorName());
        }
        wrapper.eq(RecruitMajor::getTenantId, SysUserUtils.getSysUser().getTenantId());
        wrapper.orderByDesc(RecruitMajor::getCreateTime);

        return  page(new Page<>(vo.getPageNum(), vo.getPageSize()), wrapper);
    }

    @Override
    public int addOrUpdateMajor(RecruitMajor entity) {
        int num = 0 ;
        if(StringUtils.isEmpty(entity.getId())){
            entity.setStatus("1");
            entity.setCreateBy(SysUserUtils.getSysUser().getUsername());
            entity.setCreateTime(new Date());
            num =this.baseMapper.insert(entity);
        }else{
            entity.setModifyBy(SysUserUtils.getSysUser().getUsername());
            entity.setModifyTime(new Date());
            num =this.baseMapper.updateById(entity);
        }
        return num;
    }

    @Override
    public int deleteById(String id) {
        return this.baseMapper.deleteById(id);
    }

    @Override
    public List<RecruitMajor> majorList(String tenantId) {
        QueryWrapper<RecruitMajor> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","major_name","notes", "major_picture");
        queryWrapper.eq("tenant_id",tenantId);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public RecruitMajor majorDetails(String id) {
        return this.baseMapper.selectById(id);
    }
}
